package com.project.collectAPI.entity.ImageDownLoader;
import lombok.Data;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

@Data
public class ImageDownLoader {

    //private String imageUrl = "https://example.com/image.jpg"; // HTTP URL of the image to download
    private InputStream inputStream = null;
    public static byte[] getImageBytes(String imageUrl){
        byte[] imageData = new byte[0];
        try (InputStream inputStream = new URL(imageUrl).openStream()) {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            int bytesRead;
            byte[] buffer = new byte[4096];
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            imageData = outputStream.toByteArray();
            System.out.println("Image data size: " + imageData.length);
            // Do something with the image data...
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imageData;
    }
}
